#include <bits/stdc++.h>
using namespace std;
int T,n;
int a[100002],b[100002];
int c[100002];
int ans;
void dfs(int id){
    if(id==n+1){
        for(int i=1;i<=n;i++)
            c[i]=0;
        for(int i=1;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(b[j]==b[i]){
                    if(a[j]==a[i]){
                        c[i]=a[j];
                    }
                    else
                        break;
                }
            }
        }
        int sum=0;
        for(int i=1;i<=n;i++){
            sum+=c[i];
        }
        ans=max(ans,sum);
        return;
    }
    b[id]=0;
    dfs(id+1);
    b[id]=1;
    dfs(id+1);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        ans=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            c[i]=0;
        }
        dfs(1);
        printf("%d\n",ans);
    }
    return 0;
}
